import { AIPropertyDescriptor } from "../AIProperty";
import { Vec3Field } from "./Vec3Field";

export class Vec4Field extends Vec3Field {
    protected _defaultData = { x: 0, y: 0, z: 0, w: 0 };
    protected _widget = 'Vec4';
    create(o: AIPropertyDescriptor, data: any) {
        let ret = super.create(o, data);

        let val = this._panel.getChild("value");
        let w = val.getChild('w') as IEditor.NumericInput;
        w.on("submit", this._changeHandle, this);

        if (o.step) {
            w.step = o.step;
        }
        if (null != o.min) {
            w.min = o.min;
        }
        if (null != o.max) {
            w.max = o.max;
        }
        return ret;
    }
    protected _changeHandle(e: gui.Event) {
        super._changeHandle(e);
        let vec2 = this._panel.getChild("value");
        let w = vec2.getChild('w');
        let o = this.data[this.o.name];
        o.w = Number(w.text);
    }
    protected _setValue(val: any) {
        super._setValue(val);
        let vec2 = this._panel.getChild("value");
        let w = vec2.getChild('w');
        w.text = val.w;
    }
}